package br.com.moxeon.control.operation.rules;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import br.com.moxeon.model.cash.Throw;
import br.com.moxeon.model.enums.TypeThrowTransaction;
import br.com.moxeon.model.financialaccounts.FinancialAccount;

@Service
@Scope("prototype")
public class TransferationRule extends FinancialRule{

	@Override
	public void executeOperation() {
		super.executeOperation();
		FinancialAccount  accountInput =   (FinancialAccount) getData().get("accountInput");
		FinancialAccount  accountOutput =   (FinancialAccount) getData().get("accountOutput");
		Throw throwEntityInput = (Throw) ((Throw) getData().get("throw")).cloneEntity();
		Throw throwEntityOutput = (Throw) getData().get("throw");
		
		throwEntityInput.setType(TypeThrowTransaction.SAIDA);
		throwEntityInput.setFinancialAccount(accountInput);
		throwEntityInput.setOperation(getOperation());
		
		throwEntityOutput.setType(TypeThrowTransaction.ENTRADA);
		throwEntityOutput.setFinancialAccount(accountOutput);
		throwEntityOutput.setOperation(getOperation());
		
		List<Throw> throwList = new ArrayList<Throw>();
		throwList.add(throwEntityOutput);
		throwList.add(throwEntityInput);
		getOperation().setListThorws(throwList);
		finalizeOperation();
	}
	
	@Override
	public void reverseOperation() {
		
		
	}

}
